Thread: bitwise-exclusive-OR operator: ^

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    18

    bitwise-exclusive-OR operator: ^

    Can someone please explain to me the ^ operator. I understand it in terms of zeros and ones, but not when integers are involved.

    I have the answers to the questions, but I don't understand why:

    2^6 = 4
    4^0 = 4
    4^3^2 = 5 or 2 (i don't know)
    1^3 = 3, 4, or 5(i don't know)

    I know that for the boolean expression, XOR returns 1(true) if either of the two numbers is one and returns zero(false) if both are zero or both are one. I can not see how to do XOR operator with integers. Please help or let me know where I can find the answer cuz I have looked forever.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You have to break the integers to bits (literally) for it to make sense.

    Code:
    2^6
    
    010  2
    110  6
    100  4
    
    4^0
    
    000  0
    100  4
    100  4
    
    1^3
    
    01  1
    11  3
    
    10  2
    
    4^3^2
    4^3
    100 4
    011 3
    111 7
    
    7^2
    111 7
    010 2
    101 5
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    since you understand that is a bitwise operator, in order to use it correctly with data-types you'd represent in other bases [like integers in base 10] you'd have to grasp them in binary to correctly sequence their effects in your mind. however, if you assign and rewrite your values in hexadecimal, your conceptualization could be easier.
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Questions
    By someprogr in forum C Programming
    Replies: 8
    Last Post: 12-14-2008, 06:45 PM
  2. bitwise operations with double
    By henry_kay in forum C Programming
    Replies: 2
    Last Post: 10-03-2007, 04:57 AM
  3. Exclusive or in if statement?
    By Quantum1024 in forum C Programming
    Replies: 3
    Last Post: 03-26-2005, 02:10 PM
  4. Bitwise Operators, Help!!
    By Mini__C in forum C Programming
    Replies: 6
    Last Post: 07-14-2004, 04:20 PM
  5. Characters into bitwise ints
    By Code Zer0 in forum C++ Programming
    Replies: 9
    Last Post: 04-24-2003, 08:34 AM